<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>digichef.registration.models.RegistrationManager</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="digichef-module.html">Package&nbsp;digichef</a> ::
        <a href="digichef.registration-module.html">Package&nbsp;registration</a> ::
        <a href="digichef.registration.models-module.html">Module&nbsp;models</a> ::
        Class&nbsp;RegistrationManager
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="digichef.registration.models.RegistrationManager-class.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<!-- ==================== CLASS DESCRIPTION ==================== -->
<h1 class="epydoc">Class RegistrationManager</h1><p class="nomargin-top"><span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager">source&nbsp;code</a></span></p>
<center>
<center>  <map id="uml_class_diagram_for_digichef_16" name="uml_class_diagram_for_digichef_16">
<area shape="rect" href="digichef.registration.models.RegistrationManager-class.html#activate_user" title="Validate an activation key and activate the corresponding ``User`` if valid." alt="" coords="17,36,577,55"/>
<area shape="rect" href="digichef.registration.models.RegistrationManager-class.html#create_inactive_user" title="Create a new, inactive ``User``, generates a ``RegistrationProfile`` and email its activation key to the ``User``, returning the new ``User``." alt="" coords="17,55,577,73"/>
<area shape="rect" href="digichef.registration.models.RegistrationManager-class.html#create_profile" title="Create a ``RegistrationProfile`` for a given ``User``, and return the ``RegistrationProfile``." alt="" coords="17,73,577,92"/>
<area shape="rect" href="digichef.registration.models.RegistrationManager-class.html#delete_expired_users" title="Remove expired instances of ``RegistrationProfile`` and their associated ``User``s." alt="" coords="17,92,577,111"/>
<area shape="rect" href="digichef.registration.models.RegistrationManager-class.html" title="Custom manager for the ``RegistrationProfile`` model." alt="" coords="16,11,579,112"/>
</map>
  <img src="uml_class_diagram_for_digichef_16.gif" alt='' usemap="#uml_class_diagram_for_digichef_16" ismap="ismap" class="graph-without-title" />
</center>
</center>
<hr />
<pre class="literalblock">

Custom manager for the ``RegistrationProfile`` model.

The methods defined here provide shortcuts for account creation
and activation (including generation and emailing of activation
keys), and for cleaning out expired inactive accounts.

</pre>

<!-- ==================== INSTANCE METHODS ==================== -->
<a name="section-InstanceMethods"></a>
<table class="summary" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Instance Methods</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-InstanceMethods"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="digichef.registration.models.RegistrationManager-class.html#activate_user" class="summary-sig-name">activate_user</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">activation_key</span>)</span><br />
      Validate an activation key and activate the corresponding
``User`` if valid.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager.activate_user">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="digichef.registration.models.RegistrationManager-class.html#create_inactive_user" class="summary-sig-name">create_inactive_user</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">username</span>,
        <span class="summary-sig-arg">password</span>,
        <span class="summary-sig-arg">email</span>,
        <span class="summary-sig-arg">send_email</span>=<span class="summary-sig-default">True</span>,
        <span class="summary-sig-arg">profile_callback</span>=<span class="summary-sig-default">None</span>)</span><br />
      Create a new, inactive ``User``, generates a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager.create_inactive_user">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="digichef.registration.models.RegistrationManager-class.html#create_profile" class="summary-sig-name">create_profile</a>(<span class="summary-sig-arg">self</span>,
        <span class="summary-sig-arg">user</span>)</span><br />
      Create a ``RegistrationProfile`` for a given
``User``, and return the ``RegistrationProfile``.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager.create_profile">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
<tr>
    <td width="15%" align="right" valign="top" class="summary">
      <span class="summary-type">&nbsp;</span>
    </td><td class="summary">
      <table width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
          <td><span class="summary-sig"><a href="digichef.registration.models.RegistrationManager-class.html#delete_expired_users" class="summary-sig-name">delete_expired_users</a>(<span class="summary-sig-arg">self</span>)</span><br />
      Remove expired instances of ``RegistrationProfile`` and their
associated ``User``s.</td>
          <td align="right" valign="top">
            <span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager.delete_expired_users">source&nbsp;code</a></span>
            
          </td>
        </tr>
      </table>
      
    </td>
  </tr>
</table>
<!-- ==================== METHOD DETAILS ==================== -->
<a name="section-MethodDetails"></a>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr bgcolor="#70b0f0" class="table-header">
  <td colspan="2" class="table-header">
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
      <tr valign="top">
        <td align="left"><span class="table-header">Method Details</span></td>
        <td align="right" valign="top"
         ><span class="options">[<a href="#section-MethodDetails"
         class="privatelink" onclick="toggle_private();"
         >hide private</a>]</span></td>
      </tr>
    </table>
  </td>
</tr>
</table>
<a name="activate_user"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">activate_user</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">activation_key</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager.activate_user">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <pre class="literalblock">

Validate an activation key and activate the corresponding
``User`` if valid.

If the key is valid and has not expired, return the ``User``
after activating.

If the key is not valid or has expired, return ``False``.

If the key is valid but the ``User`` is already active,
return ``False``.

To prevent reactivation of an account which has been
deactivated by site administrators, the activation key is
reset to the string ``ALREADY_ACTIVATED`` after successful
activation.

</pre>
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<a name="create_inactive_user"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">create_inactive_user</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">username</span>,
        <span class="sig-arg">password</span>,
        <span class="sig-arg">email</span>,
        <span class="sig-arg">send_email</span>=<span class="sig-default">True</span>,
        <span class="sig-arg">profile_callback</span>=<span class="sig-default">None</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager.create_inactive_user">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <pre class="literalblock">

Create a new, inactive ``User``, generates a
``RegistrationProfile`` and email its activation key to the
``User``, returning the new ``User``.

To disable the email, call with ``send_email=False``.

The activation email will make use of two templates:

``registration/activation_email_subject.txt``
    This template will be used for the subject line of the
    email. It receives one context variable, ``site``, which
    is the currently-active
    ``django.contrib.sites.models.Site`` instance. Because it
    is used as the subject line of an email, this template's
    output **must** be only a single line of text; output
    longer than one line will be forcibly joined into only a
    single line.

``registration/activation_email.txt``
    This template will be used for the body of the email. It
    will receive three context variables: ``activation_key``
    will be the user's activation key (for use in constructing
    a URL to activate the account), ``expiration_days`` will
    be the number of days for which the key will be valid and
    ``site`` will be the currently-active
    ``django.contrib.sites.models.Site`` instance.

To enable creation of a custom user profile along with the
``User`` (e.g., the model specified in the
``AUTH_PROFILE_MODULE`` setting), define a function which
knows how to create and save an instance of that model with
appropriate default values, and pass it as the keyword
argument ``profile_callback``. This function should accept one
keyword argument:

``user``
    The ``User`` to relate the profile to.

</pre>
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<a name="create_profile"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">create_profile</span>(<span class="sig-arg">self</span>,
        <span class="sig-arg">user</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager.create_profile">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <pre class="literalblock">

Create a ``RegistrationProfile`` for a given
``User``, and return the ``RegistrationProfile``.

The activation key for the ``RegistrationProfile`` will be a
SHA1 hash, generated from a combination of the ``User``'s
username and a random salt.

</pre>
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<a name="delete_expired_users"></a>
<div>
<table class="details" border="1" cellpadding="3"
       cellspacing="0" width="100%" bgcolor="white">
<tr><td>
  <table width="100%" cellpadding="0" cellspacing="0" border="0">
  <tr valign="top"><td>
  <h3 class="epydoc"><span class="sig"><span class="sig-name">delete_expired_users</span>(<span class="sig-arg">self</span>)</span>
  </h3>
  </td><td align="right" valign="top"
    ><span class="codelink"><a href="digichef.registration.models-pysrc.html#RegistrationManager.delete_expired_users">source&nbsp;code</a></span>&nbsp;
    </td>
  </tr></table>
  
  <pre class="literalblock">

Remove expired instances of ``RegistrationProfile`` and their
associated ``User``s.

Accounts to be deleted are identified by searching for
instances of ``RegistrationProfile`` with expired activation
keys, and then checking to see if their associated ``User``
instances have the field ``is_active`` set to ``False``; any
``User`` who is both inactive and has an expired activation
key will be deleted.

It is recommended that this method be executed regularly as
part of your routine site maintenance; this application
provides a custom management command which will call this
method, accessible as ``manage.py cleanupregistration``.

Regularly clearing out accounts which have never been
activated serves two useful purposes:

1. It alleviates the ocasional need to reset a
   ``RegistrationProfile`` and/or re-send an activation email
   when a user does not receive or does not act upon the
   initial activation email; since the account will be
   deleted, the user will be able to simply re-register and
   receive a new activation key.

2. It prevents the possibility of a malicious user registering
   one or more accounts and never activating them (thus
   denying the use of those usernames to anyone else); since
   those accounts will be deleted, the usernames will become
   available for use again.

If you have a troublesome ``User`` and wish to disable their
account while keeping it in the database, simply delete the
associated ``RegistrationProfile``; an inactive ``User`` which
does not have an associated ``RegistrationProfile`` will not
be deleted.

</pre>
  <dl class="fields">
  </dl>
</td></tr></table>
</div>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

      <th class="navbar" width="100%"></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Thu Apr  1 02:28:23 2010
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
